package threadcoreknowledge.createthread.stopthread;

/**
 * 如果每次循环都有sleep，则不需要每次都进行检查是否已中断，在sleep过程中会有人去检查
 */
public class RightWayStopThreadEveryLoop {

    public static void main(String[] args) throws InterruptedException {
        Runnable runnable = () -> {

            try {
                int num = 0;
                while (num <= 10000 ){
                    if (num % 100 == 0){
                        System.out.println(num+"是100的倍数");
                    }
                    num++;
                    Thread.sleep(10);
                }

            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        };

        Thread thread = new Thread(runnable);
        thread.start();
        Thread.sleep(5000);
        thread.interrupt();
    }


}
